/**
 * Created by TianJing on 2017/3/22.
 */
var companyId=common.getQueryString("companyId");
var $form=$("form");
var myRadio=$form.find(".my-radio-box");
$form.validate({
    /**
     * ignore：忽略某些元素不验证
     * @type {String}
     * 例如：ignore: ".ignore" ，忽略所有的带ignore class 的标签
     */
    ignore: ".ignore"
});
renderPage();
window.formObject = $form.submit(function() {
    var data = common.formToJson($(this));
    $.post(window.globalHost + common.companyUpdatePort, data).success(function(data) {
        layer.alert(data.res.msg);
        if ("0" == data.code) {
            //如果更新成功，重新渲染页面
            renderPage();
        }
    });
    return false;
});
function renderPage() {
    $.post(window.globalHost+common.companyInfoPort,{id:companyId}).success(function (data) {
        var record=common.transformData(data);
        common.initInputByName(record);
        renderRadio(myRadio,record["isCooperating"]);
    });
}

renderRadio=function (selector,checkedValue,noPassCauseValue) {
    var radios=$(selector).find("input[type='radio']");
    $.each(radios,function (idx,ele) {
        if(ele.value===checkedValue){
            ele.checked=true;
        }
    });
};

myLabel.addLabel(function () {
    var sendData={};
    common.openTempDialog({
        title:"添加中介公司标签",
        area:['640px', '200px'],
        content:myLabel.companyContent,
        sendData:sendData,
        FailedMsg:"请输入中介公司的标签名",
        contentOnLoad:function (layerDocument) {
            //弹窗内控件加载初始化
        },
        beforeSend:function (layerDocument) {
            var input=layerDocument.find("input");
            sendData.companyLabelName=input.val();
            return input.val();
        },
        resOk:function () {

            myLabel.labelList.append('<li class="btn">'+sendData.companyLabelName+'<i>x</i></li>')
        }
    });
});
myLabel.removeLabel();
